package aop09;

import org.aspectj.lang.ProceedingJoinPoint;

public class TimeAdvice {

    public Object time(ProceedingJoinPoint jp)throws Throwable{

        Object proxy=jp.getThis();
        Object target=jp.getTarget();
        String methodName=jp.getSignature().getName();
        Object[] args=jp.getArgs();

        System.out.println("proxy = " + proxy.getClass());
        System.out.println("target = " + target.getClass());
        System.out.println("methodName = " + methodName);
        System.out.println("args = " + args);

        long start=0;
        long end=0;
        Object result=null;

        try {
            System.out.println("开始");
            start=System.currentTimeMillis();

            result=jp.proceed();

            end=System.currentTimeMillis();
            System.out.println("结束");
        } catch (Throwable throwable) {
            end=System.currentTimeMillis();
            System.out.println("出错");
            throw throwable;
        } finally {
            System.out.println(methodName+" "+(end-start));
        }

        return result;

    }
}
